<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Code1024 - JS-canvas</title>
</head>
<body>
<canvas id="canvas1024" ></canvas>
<script type="text/javascript">
<!--
	var canvas = document.getElementById("canvas1024");
	var width = 1024, height = 1024;
	canvas.width = width;
	canvas.height = height;
	var context = canvas.getContext("2d");
	context.fillRect(0, 0, width, height);


    var imgData = context.getImageData(0, 0, width, height);
    var rgb, idx = 0;
    for (y = 0; y < height; y++){
        for (x = 0; x < width; x++){
            rgb = get_color_at(x, y);
            imgData.data[idx++] = rgb[0]&255;
            imgData.data[idx++] = rgb[1]&255;
            imgData.data[idx++] = rgb[2]&255;
            imgData.data[idx++] = parseInt(255*(1-rgb[3]/255));
        }
    }
    context.putImageData(imgData, 0, 0);

	/**
	 * 获取指定点的颜色值： r,g,b,alpha
	 * 坐标范围： (0, 0) => (1023, 1023)
	 * 颜色值范围：均为 0 - 255
 	 * 透明度： 0 - 255， 值越大越透明
	 */
	function get_color_at(x, y) {
	    var r = 0, g = 0, b = 0, a = 0;

		// {{code start}}

<?php echo $code;?>

		// {{code end}}

		return [r, g, b, a];
	}
//-->
</script>
</body>
</html>
